<template>
  <div class="user-container">
    <LeftNav class="left-nav" :active-item.sync="activeItem" />
    <div class="right-content">
      <UserInfo />
      <component
        :is="currentComponent"
        :tokens="tokens"
        :expire-time="expireTime"
      ></component>
    </div>
  </div>
</template>

<script>
import { userComponent } from "./components/config";
import LeftNav from "./components/LeftNav.vue";
import UserInfo from "./components/UserInfo.vue";
import { fetchData } from "@/utils";
import { getUserAsset } from "@/api/api";

export default {
  name: "User",
  components: { LeftNav, UserInfo },
  data() {
    return {
      userid: 1,
      activeItem: 0,
      tokens: "",
      expireTime: "",
    };
  },
  computed: {
    currentComponent() {
      return userComponent[this.activeItem];
    },
  },
  watch: {
    activeItem: function () {
      this.getUserAsset();
    },
  },
  created() {
    this.getUserAsset();
  },
  methods: {
    getUserAsset() {
      fetchData(getUserAsset, this.userid).then((res) => {
        console.log(res);
        this.tokens = res.tokens;
        this.expireTime = res.expireTime;
      });
    },
  },
};
</script>

<style lang="less" scoped>
.user-container {
  width: 1344px;
  margin: 0 auto;
  background-color: var(--user-background);
  height: calc(100vh - 60px);
  padding-bottom: 38px;
  box-sizing: border-box;
  display: flex;
  .left-nav {
    width: 155px;
    height: 100%;
    flex-shrink: 0;
  }
  .right-content {
    flex: 1;
    padding-left: 46px;
    box-sizing: border-box;
    overflow: auto;
  }
}
</style>
